package com.ruoyi.docdraw.domain;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 文档master对象 sys_doc_master
 * 
 * @author lvtian
 * @date 2025-02-26
 */
public class SysDocMaster extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** $column.columnComment */
    private Long docMasterId;

    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private String docMasterOr;

    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private String docName;

    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private String docNumber;

    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Long deptId;

    /** 文档信息 */
    private List<SysDoc> sysDocList;

    public SysDocdrawSupplier sysDocdrawSupplier;

    public SysDocdrawSupplier getSysDocdrawSupplier() {
        return sysDocdrawSupplier;
    }

    public void setSysDocdrawSupplier(SysDocdrawSupplier sysDocdrawSupplier) {
        this.sysDocdrawSupplier = sysDocdrawSupplier;
    }

    public void setDocMasterId(Long docMasterId)
    {
        this.docMasterId = docMasterId;
    }

    public Long getDocMasterId() 
    {
        return docMasterId;
    }
    public void setDocMasterOr(String docMasterOr) 
    {
        this.docMasterOr = docMasterOr;
    }

    public String getDocMasterOr() 
    {
        return docMasterOr;
    }
    public void setDocName(String docName) 
    {
        this.docName = docName;
    }

    public String getDocName() 
    {
        return docName;
    }
    public void setDocNumber(String docNumber) 
    {
        this.docNumber = docNumber;
    }

    public String getDocNumber() 
    {
        return docNumber;
    }
    public void setDeptId(Long deptId) 
    {
        this.deptId = deptId;
    }

    public Long getDeptId() 
    {
        return deptId;
    }

    public List<SysDoc> getSysDocList()
    {
        return sysDocList;
    }

    public void setSysDocList(List<SysDoc> sysDocList)
    {
        this.sysDocList = sysDocList;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("docMasterId", getDocMasterId())
            .append("docMasterOr", getDocMasterOr())
            .append("docName", getDocName())
            .append("docNumber", getDocNumber())
            .append("deptId", getDeptId())
            .append("createTime", getCreateTime())
            .append("updateTime", getUpdateTime())
            .append("sysDocList", getSysDocList())
            .toString();
    }


    /**
     * 获取List<SysDocMaster>中指定属性名的所有值
     *
     * @param list       输入的List集合
     * @param fieldName  要获取的属性名
     * @param <T>        返回值的类型
     * @return List<T>   指定属性的值集合
     */
    public static <T> Map<T, List<SysDocMaster>> getFieldValuesAsMap(List<SysDocMaster> list, String fieldName, Class<T> targetType) {
        Map<T, List<SysDocMaster>> result = new HashMap<>();
        try {
            for (SysDocMaster doc : list) {
                // 获取字段值
                Field field = SysDocMaster.class.getDeclaredField(fieldName);
                field.setAccessible(true);
                @SuppressWarnings("unchecked")
                T value = (T) field.get(doc);

                // 如果 key 已经存在，将 doc 添加到对应的 List 中
                if (result.containsKey(value)) {
                    result.get(value).add(doc);
                } else {
                    // 如果 key 不存在，创建一个新的 List 并添加到 Map 中
                    List<SysDocMaster> docList = new ArrayList<>();
                    docList.add(doc);
                    result.put(value, docList);
                }
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();  // 异常处理，根据需要调整
        }
        return result;
    }
}

